import axios from './axios.js'

// get
export function get(url, params = {}) {
    return new Promise((resolve, reject) => {
        axios
            .get(url, {
                params: params
            })
            .then(response => {
                resolve(response)
            })
            .catch(err => {
                reject(err)
            })
    })
}
export function upload(url, formData) {
    return new Promise((resolve, reject) => {
        axios.post(url, formData, {
            "Content-Type": "multipart/form-data;charset=utf-8"
        }).then(
            response => {
                resolve(response)
            },
            err => {
                reject(err)
            }
        )
    })
}
// post
export function post(url, data = {}) {
    return new Promise((resolve, reject) => {
        axios.post(url, data).then(
            response => {
                resolve(response)
            },
            err => {
                reject(err)
            }
        )
    })
}

// delete
export function del(url, data = {}) {
    return new Promise((resolve, reject) => {
        axios.delete(url, { data }).then(
            response => {
                resolve(response)
            },
            err => {
                reject(err)
            }
        )
    })
}

// put
export function put(url, data = {}) {
    return new Promise((resolve, reject) => {
        axios.put(url, data).then(
            response => {
                resolve(response)
            },
            err => {
                reject(err)
            }
        )
    })
}